/************************************************************************
  Scheme interpreter
  
  Copyright (C) 2010 Marioly Garza 

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation, either version 3 of the
  License, or (at your option) any later version.
  
  This program is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public
  License along with this program. If not, see
  <http://www.gnu.org/licenses/>.

************************************************************************/

#ifndef _UTIL_H_
#define _UTIL_H_

#include <cstdio>
#include <sstream>
#include <stdarg.h>
#include <string>
#include "sboolean.h"
#include "sstring.h"
#include "pair.h"

class util
{
    public:
        static bool is_atom(object *o);

        static bool is_string(object *o);

        static bool is_number(object *o);

        static const char* get_type(object* o);
        
        static int count(std::string str, const char c);
        
        static std::string stringtify(object* o);
        
        static std::string string_content(std::string str, char lv, char rv);

        static char* format(std::string format, ...);

        template<typename T>
            static bool is(object *o)
            {
                T *s = dynamic_cast<T*>(o);
                return (s);
            }

        template <typename T>
            static std::string to_string(T const& value) {
                std::stringstream sstr;
                sstr << value;
                return sstr.str();
            }


};

class array
{
    public:
        template<typename T>
            static int index_of(T arr[], int s, T c)
            {
                for (int i = 0; i < s; i++) {
                    if (arr[i] == c)
                        return i;
                }
                return -1;
            }
};

#endif
